package com.qf.commerce.controller;

import com.github.pagehelper.PageInfo;
import com.qf.commerce.common.dto.ReturnReasonDto;
import com.qf.commerce.common.vo.ReturnReasonVo;
import com.qf.commerce.exception.ControllerException;
import com.qf.commerce.resp.ResponseResult;
import com.qf.commerce.resp.ResponseStatus;
import com.qf.commerce.service.ReturnReasonService;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/reason")
public class ReturnReasonController {
    @Resource
    ReturnReasonService returnReasonService;
    @GetMapping("/list")
    public ResponseResult<PageInfo<ReturnReasonVo>> queryCancelReason(@RequestParam(defaultValue = "1")int page, @RequestParam(defaultValue = "20")int size){
        return ResponseResult.success(returnReasonService.queryReturnReason(page, size));
    }

    @PutMapping("/update")
    public ResponseResult<Integer> upReturnReasonById(@RequestBody ReturnReasonDto returnReasonDto){
        if(ObjectUtils.isEmpty(returnReasonDto)){
            throw new ControllerException(ResponseStatus.GET_DATA_ERROR);
        }
        return ResponseResult.success(returnReasonService.upById(returnReasonDto));
    }

    @PostMapping("/add")
    public ResponseResult<Integer> addReturnReasonById(@RequestBody ReturnReasonDto returnReasonDto){
        if(ObjectUtils.isEmpty(returnReasonDto)){
            throw new ControllerException(ResponseStatus.GET_DATA_ERROR);
        }
        return ResponseResult.success(returnReasonService.addReturnReason(returnReasonDto));
    }

    @DeleteMapping("/del")
    public ResponseResult<Integer> delReturnReasonById(@RequestBody List<Long> returnReasonId){
        if(ObjectUtils.isEmpty(returnReasonId)){
            throw new ControllerException(ResponseStatus.GET_DATA_ERROR);
        }
        return ResponseResult.success(returnReasonService.delById(returnReasonId));
    }
}
